{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 166,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11.24\n",
      "28.31\n",
      "11.24\n",
      "44.58\n",
      "16.99\n",
      "28.12\n",
      "32.82\n",
      "18.29\n",
      "22.55\n",
      "10.38\n",
      "7.73\n",
      "5.74\n",
      "9.27\n",
      "9.9\n",
      "9.82\n",
      "10.79\n",
      "31.27\n",
      "16.47\n",
      "21.12\n",
      "7.79\n",
      "9.91\n",
      "11.71\n",
      "17.03\n",
      "20.78\n",
      "9.79\n",
      "30.36\n",
      "54.04\n",
      "13.32\n",
      "-2.0\n",
      "19.5\n",
      "15.56\n",
      "23.38\n",
      "12.92\n",
      "41.38\n",
      "17.69\n",
      "16.44\n",
      "18.9\n",
      "13.5\n",
      "15.87\n",
      "25.43\n",
      "8.23\n",
      "11.96\n",
      "10.56\n",
      "1.01\n",
      "16.69\n",
      "9.22\n",
      "24.0\n",
      "16.25\n",
      "24.1\n",
      "18.06\n",
      "27.13\n",
      "22.81\n",
      "0.0\n",
      "13.39\n",
      "26.71\n",
      "17.9\n",
      "6.92\n",
      "11.99\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>variety</th>\n",
       "      <th>maxs</th>\n",
       "      <th>mins</th>\n",
       "      <th>set_close</th>\n",
       "      <th>peak</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>I</td>\n",
       "      <td>878.0</td>\n",
       "      <td>570.0</td>\n",
       "      <td>631.0</td>\n",
       "      <td>54.04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>FU</td>\n",
       "      <td>3000.0</td>\n",
       "      <td>2075.0</td>\n",
       "      <td>2105.0</td>\n",
       "      <td>44.58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>NI</td>\n",
       "      <td>149080.0</td>\n",
       "      <td>105445.0</td>\n",
       "      <td>132534.0</td>\n",
       "      <td>41.38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>AP</td>\n",
       "      <td>9769.0</td>\n",
       "      <td>7355.0</td>\n",
       "      <td>7909.0</td>\n",
       "      <td>32.82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>AG</td>\n",
       "      <td>4845.0</td>\n",
       "      <td>3691.0</td>\n",
       "      <td>4425.0</td>\n",
       "      <td>31.27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>FB</td>\n",
       "      <td>73.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>73.0</td>\n",
       "      <td>30.36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>J</td>\n",
       "      <td>2221.0</td>\n",
       "      <td>1731.0</td>\n",
       "      <td>1792.0</td>\n",
       "      <td>28.31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20190722</th>\n",
       "      <td>RI</td>\n",
       "      <td>2980.0</td>\n",
       "      <td>2326.0</td>\n",
       "      <td>2387.0</td>\n",
       "      <td>28.12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>WR</td>\n",
       "      <td>4574.0</td>\n",
       "      <td>3598.0</td>\n",
       "      <td>3747.0</td>\n",
       "      <td>27.13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191024</th>\n",
       "      <td>BB</td>\n",
       "      <td>185.0</td>\n",
       "      <td>146.0</td>\n",
       "      <td>157.0</td>\n",
       "      <td>26.71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>EG</td>\n",
       "      <td>5336.0</td>\n",
       "      <td>4254.0</td>\n",
       "      <td>4573.0</td>\n",
       "      <td>25.43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>RB</td>\n",
       "      <td>4027.0</td>\n",
       "      <td>3245.0</td>\n",
       "      <td>3333.0</td>\n",
       "      <td>24.10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>TA</td>\n",
       "      <td>5978.0</td>\n",
       "      <td>4821.0</td>\n",
       "      <td>4913.0</td>\n",
       "      <td>24.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>SC</td>\n",
       "      <td>496.0</td>\n",
       "      <td>402.0</td>\n",
       "      <td>452.0</td>\n",
       "      <td>23.38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191016</th>\n",
       "      <td>JR</td>\n",
       "      <td>3441.0</td>\n",
       "      <td>2802.0</td>\n",
       "      <td>2956.0</td>\n",
       "      <td>22.81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>P</td>\n",
       "      <td>5173.0</td>\n",
       "      <td>4221.0</td>\n",
       "      <td>5112.0</td>\n",
       "      <td>22.55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>SM</td>\n",
       "      <td>7604.0</td>\n",
       "      <td>6278.0</td>\n",
       "      <td>6297.0</td>\n",
       "      <td>21.12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>HC</td>\n",
       "      <td>3912.0</td>\n",
       "      <td>3239.0</td>\n",
       "      <td>3346.0</td>\n",
       "      <td>20.78</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>RS</td>\n",
       "      <td>4131.0</td>\n",
       "      <td>3457.0</td>\n",
       "      <td>3550.0</td>\n",
       "      <td>19.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>BU</td>\n",
       "      <td>3429.0</td>\n",
       "      <td>2884.0</td>\n",
       "      <td>2972.0</td>\n",
       "      <td>18.90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>JM</td>\n",
       "      <td>1423.0</td>\n",
       "      <td>1203.0</td>\n",
       "      <td>1255.0</td>\n",
       "      <td>18.29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>CJ</td>\n",
       "      <td>11546.0</td>\n",
       "      <td>9780.0</td>\n",
       "      <td>10657.0</td>\n",
       "      <td>18.06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>MA</td>\n",
       "      <td>2431.0</td>\n",
       "      <td>2062.0</td>\n",
       "      <td>2081.0</td>\n",
       "      <td>17.90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20190717</th>\n",
       "      <td>LR</td>\n",
       "      <td>2894.0</td>\n",
       "      <td>2459.0</td>\n",
       "      <td>2500.0</td>\n",
       "      <td>17.69</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>JD</td>\n",
       "      <td>4804.0</td>\n",
       "      <td>4105.0</td>\n",
       "      <td>4720.0</td>\n",
       "      <td>17.03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>WH</td>\n",
       "      <td>2479.0</td>\n",
       "      <td>2119.0</td>\n",
       "      <td>2341.0</td>\n",
       "      <td>16.99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20190920</th>\n",
       "      <td>PM</td>\n",
       "      <td>2398.0</td>\n",
       "      <td>2055.0</td>\n",
       "      <td>2230.0</td>\n",
       "      <td>16.69</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>Y</td>\n",
       "      <td>6322.0</td>\n",
       "      <td>5428.0</td>\n",
       "      <td>6176.0</td>\n",
       "      <td>16.47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>IC</td>\n",
       "      <td>5256.0</td>\n",
       "      <td>4514.0</td>\n",
       "      <td>4955.0</td>\n",
       "      <td>16.44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>RU</td>\n",
       "      <td>12271.0</td>\n",
       "      <td>10556.0</td>\n",
       "      <td>11883.0</td>\n",
       "      <td>16.25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>B</td>\n",
       "      <td>3475.0</td>\n",
       "      <td>2999.0</td>\n",
       "      <td>3443.0</td>\n",
       "      <td>15.87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>AU</td>\n",
       "      <td>364.0</td>\n",
       "      <td>315.0</td>\n",
       "      <td>345.0</td>\n",
       "      <td>15.56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>SN</td>\n",
       "      <td>145088.0</td>\n",
       "      <td>127830.0</td>\n",
       "      <td>138202.0</td>\n",
       "      <td>13.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>PP</td>\n",
       "      <td>8801.0</td>\n",
       "      <td>7762.0</td>\n",
       "      <td>8059.0</td>\n",
       "      <td>13.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>CF</td>\n",
       "      <td>13610.0</td>\n",
       "      <td>12010.0</td>\n",
       "      <td>12857.0</td>\n",
       "      <td>13.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>SF</td>\n",
       "      <td>6449.0</td>\n",
       "      <td>5711.0</td>\n",
       "      <td>5809.0</td>\n",
       "      <td>12.92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>L</td>\n",
       "      <td>7876.0</td>\n",
       "      <td>7033.0</td>\n",
       "      <td>7290.0</td>\n",
       "      <td>11.99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>IH</td>\n",
       "      <td>3043.0</td>\n",
       "      <td>2718.0</td>\n",
       "      <td>2967.0</td>\n",
       "      <td>11.96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>IF</td>\n",
       "      <td>3989.0</td>\n",
       "      <td>3571.0</td>\n",
       "      <td>3899.0</td>\n",
       "      <td>11.71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>M</td>\n",
       "      <td>3057.0</td>\n",
       "      <td>2748.0</td>\n",
       "      <td>3021.0</td>\n",
       "      <td>11.24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>RM</td>\n",
       "      <td>2485.0</td>\n",
       "      <td>2234.0</td>\n",
       "      <td>2356.0</td>\n",
       "      <td>11.24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>CY</td>\n",
       "      <td>21941.0</td>\n",
       "      <td>19805.0</td>\n",
       "      <td>20840.0</td>\n",
       "      <td>10.79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>FG</td>\n",
       "      <td>1518.0</td>\n",
       "      <td>1373.0</td>\n",
       "      <td>1501.0</td>\n",
       "      <td>10.56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>SR</td>\n",
       "      <td>5634.0</td>\n",
       "      <td>5104.0</td>\n",
       "      <td>5513.0</td>\n",
       "      <td>10.38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>OI</td>\n",
       "      <td>7583.0</td>\n",
       "      <td>6899.0</td>\n",
       "      <td>7269.0</td>\n",
       "      <td>9.91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>A</td>\n",
       "      <td>3642.0</td>\n",
       "      <td>3314.0</td>\n",
       "      <td>3421.0</td>\n",
       "      <td>9.90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>V</td>\n",
       "      <td>6892.0</td>\n",
       "      <td>6276.0</td>\n",
       "      <td>6328.0</td>\n",
       "      <td>9.82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>SP</td>\n",
       "      <td>4867.0</td>\n",
       "      <td>4433.0</td>\n",
       "      <td>4632.0</td>\n",
       "      <td>9.79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>CS</td>\n",
       "      <td>2380.0</td>\n",
       "      <td>2178.0</td>\n",
       "      <td>2188.0</td>\n",
       "      <td>9.27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>PB</td>\n",
       "      <td>17526.0</td>\n",
       "      <td>16047.0</td>\n",
       "      <td>16754.0</td>\n",
       "      <td>9.22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>ZN</td>\n",
       "      <td>19769.0</td>\n",
       "      <td>18265.0</td>\n",
       "      <td>18682.0</td>\n",
       "      <td>8.23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>ZC</td>\n",
       "      <td>595.0</td>\n",
       "      <td>552.0</td>\n",
       "      <td>558.0</td>\n",
       "      <td>7.79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>C</td>\n",
       "      <td>1964.0</td>\n",
       "      <td>1823.0</td>\n",
       "      <td>1847.0</td>\n",
       "      <td>7.73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>AL</td>\n",
       "      <td>14657.0</td>\n",
       "      <td>13708.0</td>\n",
       "      <td>13810.0</td>\n",
       "      <td>6.92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>CU</td>\n",
       "      <td>48367.0</td>\n",
       "      <td>45743.0</td>\n",
       "      <td>47393.0</td>\n",
       "      <td>5.74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>TF</td>\n",
       "      <td>100.0</td>\n",
       "      <td>99.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>1.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>TS</td>\n",
       "      <td>100.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20191025</th>\n",
       "      <td>T</td>\n",
       "      <td>100.0</td>\n",
       "      <td>98.0</td>\n",
       "      <td>98.0</td>\n",
       "      <td>-2.00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         variety      maxs      mins  set_close   peak\n",
       "date                                                  \n",
       "20191025       I     878.0     570.0      631.0  54.04\n",
       "20191025      FU    3000.0    2075.0     2105.0  44.58\n",
       "20191025      NI  149080.0  105445.0   132534.0  41.38\n",
       "20191025      AP    9769.0    7355.0     7909.0  32.82\n",
       "20191025      AG    4845.0    3691.0     4425.0  31.27\n",
       "20191025      FB      73.0      56.0       73.0  30.36\n",
       "20191025       J    2221.0    1731.0     1792.0  28.31\n",
       "20190722      RI    2980.0    2326.0     2387.0  28.12\n",
       "20191025      WR    4574.0    3598.0     3747.0  27.13\n",
       "20191024      BB     185.0     146.0      157.0  26.71\n",
       "20191025      EG    5336.0    4254.0     4573.0  25.43\n",
       "20191025      RB    4027.0    3245.0     3333.0  24.10\n",
       "20191025      TA    5978.0    4821.0     4913.0  24.00\n",
       "20191025      SC     496.0     402.0      452.0  23.38\n",
       "20191016      JR    3441.0    2802.0     2956.0  22.81\n",
       "20191025       P    5173.0    4221.0     5112.0  22.55\n",
       "20191025      SM    7604.0    6278.0     6297.0  21.12\n",
       "20191025      HC    3912.0    3239.0     3346.0  20.78\n",
       "20191025      RS    4131.0    3457.0     3550.0  19.50\n",
       "20191025      BU    3429.0    2884.0     2972.0  18.90\n",
       "20191025      JM    1423.0    1203.0     1255.0  18.29\n",
       "20191025      CJ   11546.0    9780.0    10657.0  18.06\n",
       "20191025      MA    2431.0    2062.0     2081.0  17.90\n",
       "20190717      LR    2894.0    2459.0     2500.0  17.69\n",
       "20191025      JD    4804.0    4105.0     4720.0  17.03\n",
       "20191025      WH    2479.0    2119.0     2341.0  16.99\n",
       "20190920      PM    2398.0    2055.0     2230.0  16.69\n",
       "20191025       Y    6322.0    5428.0     6176.0  16.47\n",
       "20191025      IC    5256.0    4514.0     4955.0  16.44\n",
       "20191025      RU   12271.0   10556.0    11883.0  16.25\n",
       "20191025       B    3475.0    2999.0     3443.0  15.87\n",
       "20191025      AU     364.0     315.0      345.0  15.56\n",
       "20191025      SN  145088.0  127830.0   138202.0  13.50\n",
       "20191025      PP    8801.0    7762.0     8059.0  13.39\n",
       "20191025      CF   13610.0   12010.0    12857.0  13.32\n",
       "20191025      SF    6449.0    5711.0     5809.0  12.92\n",
       "20191025       L    7876.0    7033.0     7290.0  11.99\n",
       "20191025      IH    3043.0    2718.0     2967.0  11.96\n",
       "20191025      IF    3989.0    3571.0     3899.0  11.71\n",
       "20191025       M    3057.0    2748.0     3021.0  11.24\n",
       "20191025      RM    2485.0    2234.0     2356.0  11.24\n",
       "20191025      CY   21941.0   19805.0    20840.0  10.79\n",
       "20191025      FG    1518.0    1373.0     1501.0  10.56\n",
       "20191025      SR    5634.0    5104.0     5513.0  10.38\n",
       "20191025      OI    7583.0    6899.0     7269.0   9.91\n",
       "20191025       A    3642.0    3314.0     3421.0   9.90\n",
       "20191025       V    6892.0    6276.0     6328.0   9.82\n",
       "20191025      SP    4867.0    4433.0     4632.0   9.79\n",
       "20191025      CS    2380.0    2178.0     2188.0   9.27\n",
       "20191025      PB   17526.0   16047.0    16754.0   9.22\n",
       "20191025      ZN   19769.0   18265.0    18682.0   8.23\n",
       "20191025      ZC     595.0     552.0      558.0   7.79\n",
       "20191025       C    1964.0    1823.0     1847.0   7.73\n",
       "20191025      AL   14657.0   13708.0    13810.0   6.92\n",
       "20191025      CU   48367.0   45743.0    47393.0   5.74\n",
       "20191025      TF     100.0      99.0      100.0   1.01\n",
       "20191025      TS     100.0     100.0      100.0   0.00\n",
       "20191025       T     100.0      98.0       98.0  -2.00"
      ]
     },
     "execution_count": 166,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# encoding: utf-8\n",
    "import pandas as pd\n",
    "from pandas import *\n",
    "import datetime\n",
    "import json\n",
    "from pymongo import MongoClient\n",
    "from collections import defaultdict\n",
    "\n",
    "pd.set_option('display.width', None)  # 设置字符显示宽度\n",
    "pd.set_option('display.max_rows', None)  # 设置显示最大行\n",
    "pd.set_option('display.max_columns', None)  # 设置显示最大行\n",
    "\n",
    "client = MongoClient('localhost', 27017)\n",
    "db = client.futures\n",
    "indexMarket = db.indexMarket\n",
    "peaks = db.peaks\n",
    "unit=db.unit\n",
    "\n",
    "db.peaks.delete_many ({})\n",
    "start='20190101'\n",
    "indexMarket = DataFrame(list(indexMarket.find({'date': {'$gte': start}})))\n",
    "unit = DataFrame(list(unit.find()))\n",
    "var=unit['variety']\n",
    "for i in set(var):\n",
    "    try:\n",
    "        df = indexMarket[indexMarket['variety'] == i]\n",
    "#         maxs=df.set_high.idxmin()#最小值的索引\n",
    "#         print(maxs)\n",
    "        #         date=df[['date'][-1]]\n",
    "        df = df[['date', 'variety', 'set_open', 'set_close', 'set_high', 'set_low']]\n",
    "        df.set_index('date', inplace=True)\n",
    "        maxs = df[['set_high']].stack().max()\n",
    "#         print(maxs)\n",
    "        \n",
    "        mins = df[[ 'set_low']].stack().min()\n",
    "        gains = round(((maxs / mins-1) * 100), 2)\n",
    "#         print(gains)\n",
    "        lesses = round(((mins / maxs-1) * 100), 2)\n",
    "#         print(lesses)\n",
    "        peak = (lambda x: gains if mins < df['set_close'][-1] else lesses)(1)\n",
    "        print(peak)\n",
    "        df2 = df.copy()\n",
    "        df2['maxs'] = maxs\n",
    "        df2['mins'] = mins\n",
    "        df2['peak'] = peak\n",
    "        df2 = df2.reset_index()\n",
    "        begin =df2.date[1]\n",
    "        df2 = df2[['date','variety', 'maxs', 'mins', 'set_close', 'peak']][-1:]\n",
    "        peaks.insert_many(json.loads(df2.T.to_json()).values())\n",
    "#         print('写入数据成功')\n",
    "#         print(json.loads(df2.T.to_json()).values())\n",
    "    except:\n",
    "        print('error')       \n",
    "df=DataFrame(list(peaks.find()))\n",
    "df=df[['date','variety','maxs','mins','set_close','peak']]\n",
    "df=df.set_index('date')\n",
    "df.sort_values(by=\"peak\",ascending= False)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "#幅度排序\n",
    "df=DataFrame(list(peaks.find().sort('peak',-1)))\n",
    "df=df[['date','variety','maxs','mins','set_close','peak']]\n",
    "df=df.set_index('date')\n",
    "    \n",
    "df['begin']=begin\n",
    "# df=pd.date_range(start=start,periods=20)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "#删除表（集合）\n",
    "peaks.drop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
